import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"
import { promission } from "./permission"

const lazyLoadingComponents = () => {
    return {
        loginView: () => import("@/views/LoginView.vue"),
        errPage: () => import("@/views/404.vue")
    }
}

export const staticRoutes: Array<RouteRecordRaw> = [
    {
        path: "/",
        redirect: "/login"
    },
    {
        path: "/login",
        name: "Login",
        component: lazyLoadingComponents().loginView,
        meta: { title: "登录", roles: ["admin", "user"] }
    },
    {
        path: "/errPage",
        name: "ErrPage",
        component: lazyLoadingComponents().errPage,
        meta: { title: "404", roles: ["admin", "user"] }
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: staticRoutes,
    linkExactActiveClass: "h-router-active"
})

promission(router)

export default router
